using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLIEFPA
    {
        public DataRow Convert2LIEFPA(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLIEFPA(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LSPMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LSPLIEFNR"] = " ".PadRight(8 ); 
         dwReturn["LSPPACKSL"] = " ".PadRight(4 ); 
         dwReturn["LSPPATYP"] = " ".PadRight(2 ); 
         dwReturn["LSPPANRLIEF"] = " ".PadRight(20 ); 
         dwReturn["LSPBEZ"] = " ".PadRight(40 ); 
         dwReturn["LSPLEIH"] = " ".PadRight(1 ); 
         dwReturn["LSPPRME"] = " ".PadRight(0 ); 
         dwReturn["LSPBEM"] = " ".PadRight(40 ); 
         dwReturn["LSPRUECKVPR"] = " ".PadRight(0 ); 
         dwReturn["LSPLBEDAT"] = " ".PadRight(8 ); 
         dwReturn["LSPBESTAND01"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND02"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND03"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND04"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND05"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND06"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND07"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND08"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND09"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND10"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND11"] = " ".PadRight(0 ); 
         dwReturn["LSPBESTAND12"] = " ".PadRight(0 ); 
         dwReturn["LSPFILLER"] = " ".PadRight(243 ); 
         dwReturn["LSPAENDZL"] = " ".PadRight(0 ); 
         dwReturn["LSPAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["LSPAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["LSPNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["LSPNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLIEFPA(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLIEFPA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLIEFPA(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLIEFPA(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLIEFPA(dwLocal, ITXDBVERSION);
            }
            UpdateLIEFPA(dwLocal);
        }
        public void InsertLIEFPA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LIEFPA(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLIEFPA(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LIEFPA WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LIEFPA  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LIEFPA";
            Return = Result;
            return Return;
        }
        public void DeleteLIEFPA(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LIEFPA   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLIEFPA(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LIEFPA SET "
                    +"LSPMANDANT= :LSPMANDANT,"
                    +"LSPLIEFNR= :LSPLIEFNR,"
                    +"LSPPACKSL= :LSPPACKSL,"
                    +"LSPPATYP= :LSPPATYP,"
                    +"LSPPANRLIEF= :LSPPANRLIEF,"
                    +"LSPBEZ= :LSPBEZ,"
                    +"LSPLEIH= :LSPLEIH,"
                    +"LSPPRME= :LSPPRME,"
                    +"LSPBEM= :LSPBEM,"
                    +"LSPRUECKVPR= :LSPRUECKVPR,"
                    +"LSPLBEDAT= :LSPLBEDAT,"
                    +"LSPBESTAND01= :LSPBESTAND01,"
                    +"LSPBESTAND02= :LSPBESTAND02,"
                    +"LSPBESTAND03= :LSPBESTAND03,"
                    +"LSPBESTAND04= :LSPBESTAND04,"
                    +"LSPBESTAND05= :LSPBESTAND05,"
                    +"LSPBESTAND06= :LSPBESTAND06,"
                    +"LSPBESTAND07= :LSPBESTAND07,"
                    +"LSPBESTAND08= :LSPBESTAND08,"
                    +"LSPBESTAND09= :LSPBESTAND09,"
                    +"LSPBESTAND10= :LSPBESTAND10,"
                    +"LSPBESTAND11= :LSPBESTAND11,"
                    +"LSPBESTAND12= :LSPBESTAND12,"
                    +"LSPFILLER= :LSPFILLER,"
                    +"LSPAENDZL= :LSPAENDZL,"
                    +"LSPAENDBEN= :LSPAENDBEN,"
                    +"LSPAENDDAT= :LSPAENDDAT,"
                    +"LSPNEUBEN= :LSPNEUBEN,"
                    +"LSPNEUDAT= :LSPNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LSPMANDANT", OracleType.NVarChar).Value = dwData["LSPMANDANT"].ToString(); 
          or1.Parameters.Add("LSPLIEFNR", OracleType.NVarChar).Value = dwData["LSPLIEFNR"].ToString(); 
          or1.Parameters.Add("LSPPACKSL", OracleType.NVarChar).Value = dwData["LSPPACKSL"].ToString(); 
          or1.Parameters.Add("LSPPATYP", OracleType.NVarChar).Value = dwData["LSPPATYP"].ToString(); 
          or1.Parameters.Add("LSPPANRLIEF", OracleType.NVarChar).Value = dwData["LSPPANRLIEF"].ToString(); 
          or1.Parameters.Add("LSPBEZ", OracleType.NVarChar).Value = dwData["LSPBEZ"].ToString(); 
          or1.Parameters.Add("LSPLEIH", OracleType.NVarChar).Value = dwData["LSPLEIH"].ToString(); 
          or1.Parameters.Add("LSPPRME", OracleType.NVarChar).Value = dwData["LSPPRME"].ToString(); 
          or1.Parameters.Add("LSPBEM", OracleType.NVarChar).Value = dwData["LSPBEM"].ToString(); 
          or1.Parameters.Add("LSPRUECKVPR", OracleType.NVarChar).Value = dwData["LSPRUECKVPR"].ToString(); 
          or1.Parameters.Add("LSPLBEDAT", OracleType.NVarChar).Value = dwData["LSPLBEDAT"].ToString(); 
          or1.Parameters.Add("LSPBESTAND01", OracleType.NVarChar).Value = dwData["LSPBESTAND01"].ToString(); 
          or1.Parameters.Add("LSPBESTAND02", OracleType.NVarChar).Value = dwData["LSPBESTAND02"].ToString(); 
          or1.Parameters.Add("LSPBESTAND03", OracleType.NVarChar).Value = dwData["LSPBESTAND03"].ToString(); 
          or1.Parameters.Add("LSPBESTAND04", OracleType.NVarChar).Value = dwData["LSPBESTAND04"].ToString(); 
          or1.Parameters.Add("LSPBESTAND05", OracleType.NVarChar).Value = dwData["LSPBESTAND05"].ToString(); 
          or1.Parameters.Add("LSPBESTAND06", OracleType.NVarChar).Value = dwData["LSPBESTAND06"].ToString(); 
          or1.Parameters.Add("LSPBESTAND07", OracleType.NVarChar).Value = dwData["LSPBESTAND07"].ToString(); 
          or1.Parameters.Add("LSPBESTAND08", OracleType.NVarChar).Value = dwData["LSPBESTAND08"].ToString(); 
          or1.Parameters.Add("LSPBESTAND09", OracleType.NVarChar).Value = dwData["LSPBESTAND09"].ToString(); 
          or1.Parameters.Add("LSPBESTAND10", OracleType.NVarChar).Value = dwData["LSPBESTAND10"].ToString(); 
          or1.Parameters.Add("LSPBESTAND11", OracleType.NVarChar).Value = dwData["LSPBESTAND11"].ToString(); 
          or1.Parameters.Add("LSPBESTAND12", OracleType.NVarChar).Value = dwData["LSPBESTAND12"].ToString(); 
          or1.Parameters.Add("LSPFILLER", OracleType.NVarChar).Value = dwData["LSPFILLER"].ToString(); 
          or1.Parameters.Add("LSPAENDZL", OracleType.NVarChar).Value = dwData["LSPAENDZL"].ToString(); 
          or1.Parameters.Add("LSPAENDBEN", OracleType.NVarChar).Value = dwData["LSPAENDBEN"].ToString(); 
          or1.Parameters.Add("LSPAENDDAT", OracleType.NVarChar).Value = dwData["LSPAENDDAT"].ToString(); 
          or1.Parameters.Add("LSPNEUBEN", OracleType.NVarChar).Value = dwData["LSPNEUBEN"].ToString(); 
          or1.Parameters.Add("LSPNEUDAT", OracleType.NVarChar).Value = dwData["LSPNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
